/**
 * @file   MultiDnsResolver.hpp
 * @author Yuan Liu <liuyuan@net.pku.edu.cn>
 * @date   Thu Sep 27 16:28:26 2007
 * 
 * @brief  A multi-thread dns resolver
 *
 * Use getaddrinfo to get thread-safty
 *
 * @see getaddrinfo
 * @see getnameinfo
 */

#ifndef __MULTIDNSRUSOLVER_HPP
#define __MULTIDNSRUSOLVER_HPP


#include <map>
#include <string>
#include <vector>


class MultiDnsResolver
{
public:
    MultiDnsResolver(int threadNum = 10);
    ~MultiDnsResolver();
    
    /// the function
    std::string GetIP(const std::string& crDomainName);

    /// muti-thread get
    int GetIPList(std::map<std::string, std::string>& rDomainIpMap);
    
private:
    static void* StartThread(void* arg);
    void ThreadResolve(int idx);
    
private:
    int mThreadNum;
    std::vector<std::vector<std::map<std::string, std::string>::iterator> > mJobPool;
};

struct ThreadArg
{
    MultiDnsResolver* thd;
    int               idx;
};

#endif
